package io.gitee.zhangbinhub.admin.gateway.consumer

import io.gitee.zhangbinhub.acp.boot.log.LogAdapter
import io.gitee.zhangbinhub.admin.common.constant.RouteConstant
import io.gitee.zhangbinhub.admin.gateway.repo.RouteRedisRepository
import org.springframework.stereotype.Component
import java.util.function.Consumer

/**
 * @author zhang by 18/03/2019
 * @since JDK 11
 */
@Component
class UpdateRouteConsumerProcess(
    private val logAdapter: LogAdapter,
    private val routeRedisRepository: RouteRedisRepository
) : Consumer<String> {
    override fun accept(message: String) {
        logAdapter.info("收到 kafka 消息：$message")
        if (RouteConstant.UPDATE_GATEWAY_ROUTES == message) {
            Thread {
                logAdapter.info("开始更新路由信息...")
                routeRedisRepository.refreshRoute()
                logAdapter.info("更新路由信息完成!")
            }.apply {
                this.isDaemon = true
            }.start()
        }
    }
}
